#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <windows.h>
#include "Hero.h"

using namespace std;

//Default constructor
Hero::Hero()
{
    name = "";
    startingHealth = 100;
    startingMinDamage = 10;
    startingMaxDamage = 20;
    startingArmor = 5;
    
    curHealth = startingHealth;
    maxHealth = startingHealth;
    minDamage = startingMinDamage;
    maxDamage = startingMaxDamage;
    armor = startingArmor;
    criticalStrikeChance = 10;
    
    srand(static_cast<unsigned int>(time(0))); // seed random number
}

Hero::~Hero()
{
    
}

void Hero::setName()
{
    cout << "Please enter a name for your hero.\n";
    cout << "Hero Name: ";
    cin >> name;
    cout << "\nWelcome " << name << "!\n\n";
}

void Hero::setCurHealth(int newHealth)
{
    curHealth = newHealth;
}

void Hero::resetHealth()
{
    curHealth = maxHealth;
}

int Hero::getDamage()
{
    int damage = 0;
    //randomNumber = rand() % 20 + 1;
    damage = (rand() % (maxDamage - minDamage)) + minDamage;
    
    if (criticalStrike == true)
    {
        damage = damage * criticalStrikeMultiplier;
    }
    
    return damage;
}

void Hero::setCriticalStrike()
{
    int critSeed = rand() % 100 + 1;
    
    if (criticalStrikeChance >= critSeed)
    {
        criticalStrike = true;
    }
    else
    {
        criticalStrike = false;
    }
}

void Hero::displayStats()
{
    cout << "===========================" << endl;
    cout << "Hero: " << name << endl;
    cout << "Health: " << curHealth << " / " << maxHealth << endl;
    cout << "Damage: " << minDamage << " - " << maxDamage << endl;
    cout << "Armor: " << armor << endl;
    cout << "===========================" << endl;   
}

void Hero::difficultySelection()
{
    int difficulty = 0;
    while (validDifficultySelection(difficulty) == false)
    {
        cout << "Difficulty Selection:\n\n";
        cout << "1. Easy.\n";
        cout << "2. Normal.\n";
        cout << "3. Hard.\n\n";
        cout << "Select one of the following choices: ";
        cin >> difficulty;
        cout << endl;

        if (validDifficultySelection(difficulty) == false)
        {
            cout << "Invalid choice, please select choices 1-3.\n\n";
            Sleep(2000);
        }
    }
}

bool Hero::validDifficultySelection(int difficulty)
{
    bool validSelection;
    if (difficulty < 1 || difficulty > 3)
    {
        validSelection = false;
    }
    else
    {
        validSelection = true;
    }
    
    return validSelection;
}